package com.lagou.sqlSession;

import com.lagou.builder.XMLConfigBuilder;
import com.lagou.com.lagou.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    private Configuration configuration;

    public SqlSessionFactoryBuilder() {
        this.configuration = new Configuration();
    }

    public SqlSessionFactory build(InputStream inputStream) throws PropertyVetoException, DocumentException {
        //解析配置文件封装Configuration
        XMLConfigBuilder xmlConfigurationBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigurationBuilder.parseRootXMLConfig(inputStream);
        //返回sqlsession工厂对象
        return new DefaultSqlSessionFactory(configuration);
    }
}
